package com.ly.lw.styledo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ly.lw.styledo.R;
import com.ly.lw.styledo.bean.CtgListBean;

import java.util.List;

/**
 * 分类ListView的适配器
 *
 * @author 王学玲
 *         Created by T400 on 15-7-7.
 */
public class CategoryListAdapter extends AppBaseAdapter<CtgListBean> {

    private int selectItem=-1;
    private Context context;

    public CategoryListAdapter(List<CtgListBean> list, Context context) {
        super(list, context);
        this.context=context;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vHolder = null;
        if (convertView==null) {
            convertView=inflater.inflate(R.layout.category_dis_lv_item,parent,false);
            vHolder=new ViewHolder(convertView);
            convertView.setTag(vHolder);
        } else {
            vHolder= (ViewHolder) convertView.getTag();
        }
        vHolder.cateName.setText(list.get(position).getCate_nm());

        if(position==selectItem){
            convertView.setBackgroundResource(R.color.white);
            vHolder.cateName.setTextColor(context.getResources().getColor(R.color.simidared));

        }else {
            convertView.setBackgroundResource(R.color.floralwhite);
            vHolder.cateName.setTextColor(context.getResources().getColor(R.color.darkgray));
        }

        return convertView;
    }

    public static class ViewHolder {
        private TextView cateName;

        public ViewHolder(View itemView) {
            cateName = (TextView) itemView.findViewById(R.id.category_dis_lv_item);
        }
    }

    public void setSelectItem(int selectItem){
        this.selectItem=selectItem;
    }
}
